<html>
<head><meta charset="utf-8"><title>unsizing coercion · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unsizing.20coercion.html">unsizing coercion</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221657550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unsizing%20coercion/near/221657550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unsizing.20coercion.html#221657550">(Jan 05 2021 at 15:16)</a>:</h4>
<p>why do we not allow the following?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">A</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">U</span>: <span class="o">?</span><span class="nb">Sized</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="o">'</span><span class="nb">static</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">B</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">U</span><span class="o">&gt;</span><span class="p">);</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">B</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">U</span>: <span class="o">?</span><span class="nb">Sized</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">U</span><span class="p">);</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span><span class="p">([</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="n">B</span><span class="p">([</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="mi">1</span><span class="p">]));</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">y</span>: <span class="kp">&amp;</span><span class="nc">A</span><span class="o">&lt;</span><span class="p">[</span><span class="kt">u32</span><span class="p">;</span><span class="w"> </span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="p">[</span><span class="kt">u32</span><span class="p">]</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="221657643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unsizing%20coercion/near/221657643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unsizing.20coercion.html#221657643">(Jan 05 2021 at 15:16)</a>:</h4>
<p>changing <code>A</code> to <code>struct A&lt;T, U: ?Sized + 'static&gt;(T, B&lt;[u32; 1], U&gt;);</code> does compile</p>



<a name="221657744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unsizing%20coercion/near/221657744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unsizing.20coercion.html#221657744">(Jan 05 2021 at 15:17)</a>:</h4>
<p>so why is it forbidden that the last field shares a generic param with other struct fields even though that generic param remains the same</p>



<a name="221660719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unsizing%20coercion/near/221660719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unsizing.20coercion.html#221660719">(Jan 05 2021 at 15:41)</a>:</h4>
<p>opened <a href="https://github.com/rust-lang/rust/pull/80726">https://github.com/rust-lang/rust/pull/80726</a> which seems to work as expected</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>